package mylibrary.excel;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;

//import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;


public class TestExcel {

	public static void main(String[] args) {
		
		if(args.length < 3){
			//print log
		}else{
			TestExcel te = new TestExcel();
			te.excelTest(args[0], args[1], args[2]);
			
		}

	}
	
	public void excelTest(String filePath, String fileName,String password) {

		try {
			String fullFilePath = filePath + System.getProperty("file.separator") + fileName;
			String npFullFilePath = filePath + System.getProperty("file.separator") + "NotProtected.xls";
			
			OutputStream outStream = new FileOutputStream(new File(npFullFilePath));
					
			InputStream inputStream = new FileInputStream(fullFilePath);
			//Biff8EncryptionKey.setCurrentUserPassword(password);

			POIFSFileSystem poiFileSystem = new POIFSFileSystem(inputStream);

			HSSFWorkbook workbook = new HSSFWorkbook(poiFileSystem);
			workbook.write(outStream);
			
			//Added by gaoshuai
			POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(filePath + System.getProperty("file.separator") + "NotProtected.xls"));   
			HSSFWorkbook wb = new HSSFWorkbook(fs);   
			HSSFSheet sheet = wb.getSheet("");
			HSSFRow row = sheet.getRow(13); 		//第 14 行
			//HSSFCell cell = row.getCell(6);			//第 G 列
			//System.out.println(cell.getCellFormula());  //取出公式
			//System.out.println(cell.getNumericCellValue());  // 如果是数值类型的，取出值
			//System.out.println(cell.getStringCellValue());   // 如果是字符串类型的，取出值
			

			
		} catch (Exception ioe) {
			ioe.printStackTrace();
		}

	}
 
 
}
